import {userInfo} from '@/api/http'
import {removeToken} from "@/common/token";

const state = {
    roles: [],
}


const getters = {
    roles:state=>state.roles
}

const actions = {
    USERINFO({commit}) {
        return new Promise((resolve, reject)=>{
            userInfo().then(res=>{
                let {data} = res.data
                commit('SETUSERROLE', data.roles)
                resolve(data)
            })
        })
    },
    LOGOUT({commit}) {
        //清除token
        removeToken();
        commit('SETUSERROLE', [])
    }
}

const mutations = {
    SETUSERROLE:(state, d)=>{
        state.roles = d;
    }
}

export default {
    state,
    getters,
    actions,
    mutations,
}